package com.xzp.bams.dao;

import com.xzp.bams.entity.Account;

import java.util.Arrays;

/**
 * @TODO
 * @Author xu
 * 2025/3/7
 */
public class ArrayDao implements IDao<Account, Account[]> {

    private Account[] accs = new Account[100];
    private int index = 0;

    private Long id = 100000000000000000L;

    @Override
    public Long getId(){
        return id;
    }

    @Override
    public void setId(Long id){
        this.id = id;
    }

    public boolean insert(Account acc) {
        if (index >= accs.length) {
            accs = Arrays.copyOf(accs, accs.length * 3 / 2 + 1);
        }
        accs[index++] = acc;
        return true;
    }

    public Account selectOne(Long id, String password) {
        for (int i = 0; i < index; i++) {
            if (accs[i].getId().equals(id) && accs[i].getPassword().equals(password)) {
                return accs[i];// 不同点
            }
        }
        return null;
    }

    public Account selectOne(Long id) {
        for (int i = 0; i < index; i++) {
            if (accs[i].getId().equals(id)) {
                return accs[i];// 不同点
            }
        }
        return null;
    }

    public Account[] selectAll() {
        return accs;
    }
}


